package com.linjj.seckill.controller;

import com.linjj.seckill.access.AccessLimit;
import com.linjj.seckill.domain.User;
import com.linjj.seckill.service.IUserService;
import com.linjj.seckill.vo.CodeMsg;
import com.linjj.seckill.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    public IUserService userService;

    @AccessLimit(seconds = 5,maxCount = 5)
    @PostMapping("/updateAddress")
    @ResponseBody
    public Result updateAddress(HttpServletRequest request, User user,String address){
        user.setAddress(address);
        boolean update = userService.updateUser(user,request);
        if(update){
            return Result.success(true);
        }else{
            return Result.error(CodeMsg.SERVER_ERROR);
        }
    }
}
